package com.wanyang.controller;

import com.wanyang.dto.PageDTO;
import com.wanyang.dto.SearchDTO;
import com.wanyang.service.PostCommentService;
import com.wanyang.service.PostService;
import com.wanyang.vo.ApiResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags="帖子查询api")
@RestController
@RequestMapping("post/query")
public class PostController {

    @Autowired
    private PostService postService;

    @Autowired
    private PostCommentService postCommentService;

    @ApiOperation(value = "帖子查询 - 分类")
    @GetMapping("category")
    public ApiResult queryCategory(@RequestParam Integer areaId) {

        return ApiResult.success(postService.queryAreaCategories(areaId), null);
    }

    @ApiOperation(value = "帖子查询 - 置顶")
    @GetMapping("top")
    public ApiResult queryTopPost(@RequestParam Integer postCategoryId, @RequestParam Integer areaId) {

        return ApiResult.success(postService.queryTopPost(postCategoryId, areaId), null);
    }

    @ApiOperation(value = "帖子查询 - 列表")
    @GetMapping("list")
    public ApiResult list(@RequestParam Integer postCategoryId, @RequestParam Integer areaId, PageDTO pageDTO) {

        return ApiResult.success(postService.queryVOList(postCategoryId, areaId, pageDTO), null);
    }

    @ApiOperation(value = "帖子查询 - 详情")
    @GetMapping("detail")
    public ApiResult detail(@RequestParam Integer postId) {

        return ApiResult.success(postService.queryDetail(postId), null);
    }

    @ApiOperation(value = "帖子查询 - 主评论分页")
    @GetMapping("principalComment")
    public ApiResult queryPrincipalComment(@RequestParam Integer postId, PageDTO pageDTO) {

        return ApiResult.success(postCommentService.queryPrincipalCommentPage(postId, pageDTO), null);
    }

    @ApiOperation(value = "帖子查询 - 子评论分页")
    @GetMapping("subComment")
    public ApiResult querySubComment(@RequestParam Integer postCommentId, PageDTO pageDTO) {

        return ApiResult.success(postCommentService.querySubCommentPage(postCommentId, pageDTO), null);
    }

    @ApiOperation(value = "查看某个人的帖子列表")
    @GetMapping("member/{memberId}")
    public ApiResult queryMemberPosts(@PathVariable Integer memberId, PageDTO pageDTO) {

        return ApiResult.success(postService.queryMemberPosts(memberId, pageDTO), null);
    }


    @ApiOperation(value = "搜索")
    @GetMapping("search")
    public ApiResult search(SearchDTO searchDTO) {
        return ApiResult.success(postService.search(searchDTO), null);
    }
}
